<button class="btn btn-outline-secondary" :disabled="!selectedIds.length" @click="handleBatchPriceOpen()">批量改价格
</button>
<el-dialog v-if="typeof filter.batch_price !== 'undefined'" title="修改价格"
           :visible.sync="filter.batch_price.dialog.dialogFormVisible">
  <el-form ref="batchPriceForm" label-position="top" :model="filter.batch_price" label-width="100px">
    <el-row>
      <el-col :span="4">
        <el-radio @change="handleRadioChange" name="select_type" v-model="filter.batch_price.select_type" label="1"
                  border>按现有价格
        </el-radio>
      </el-col>
      <el-col :span="10">
        <el-input :disabled="filter.batch_price.input_dis_1" v-model="filter.batch_price.input_val_1" type="number"
                  placeholder="如果减少，可输入负数">
          <el-select @change="handleSelectChange" v-model="filter.batch_price.exc_type" slot="prepend"
                     style="width: 130px;">
            <el-option value="amount" label="金额"></el-option>
            <el-option value="percent" label="百分比"></el-option>
          </el-select>
        </el-input>
        <span v-if="filter.batch_price.percentShow">%</span>
      </el-col>
    </el-row>
    <el-row style="margin-top: 20px;">
      <el-col :span="4">
        <el-radio @change="handleRadioChange" name="select_type" v-model="filter.batch_price.select_type" label="2"
                  border>直接修改为
        </el-radio>
      </el-col>
      <el-col :span="5">
        <el-input :disabled="filter.batch_price.input_dis_2" v-model="filter.batch_price.input_val_2" type="number"
                  placeholder="示例：1.00"></el-input>
      </el-col>
    </el-row>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="filter.batch_price.dialog.dialogFormVisible = false">{{ __('common.cancel') }}</el-button>
    <el-button type="primary" @click="saveBatchPrice">{{ __('common.confirm') }}</el-button>
  </div>
</el-dialog>
@push("footer")
  <script>
    $(function () {
      app.$set(app.filter, "batch_price", {
        "dialog": {
          "dialogFormVisible": false,
        },
        "percentShow": false,
        "exc_type": "amount",
        "select_type": "1",
        "input_dis_1": false,
        "input_dis_2": true,
        "input_val_1": '',
        "input_val_2": ''
      });
      app.handleBatchPriceOpen = function () {
        app.filter.batch_price.dialog.dialogFormVisible = true;
      };
      app.handleSelectChange = function (value) {
        if (value == 'percent') {
          app.filter.batch_price.percentShow = true;
        } else {
          app.filter.batch_price.percentShow = false;
        }
      };
      app.handleRadioChange = function (value) {
        if (value == "1") {
          app.filter.batch_price.input_dis_1 = false;
          app.filter.batch_price.input_dis_2 = true;
        }
        if (value == "2") {
          app.filter.batch_price.input_dis_1 = true;
          app.filter.batch_price.input_dis_2 = false;
        }
      };
      app.saveBatchPrice = function () {
        $http.put("{{admin_route('product_price.batch_setting')}}", {
          ids: app.selectedIds,
          selectType: app.filter.batch_price.select_type,
          excType: app.filter.batch_price.exc_type,
          value1: app.filter.batch_price.input_val_1,
          value2: app.filter.batch_price.input_val_2
        }).then((res) => {
          app.filter.batch_price.dialog.dialogFormVisible = false;
          layer.msg(res.message);
          location.reload();
        })
      }
    });
  </script>
@endpush
